package com.woniu.cq.medical.service.impl;

import com.woniu.cq.medical.controller.form.PrescriptionForm;
import com.woniu.cq.medical.entity.PrescriptionInfo;
import com.woniu.cq.medical.dao.PrescriptionInfoMapper;
import com.woniu.cq.medical.service.PrescriptionInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2020-09-08
 */
@Service
public class PrescriptionInfoServiceImpl extends ServiceImpl<PrescriptionInfoMapper, PrescriptionInfo> implements PrescriptionInfoService {
    @Autowired
    private PrescriptionInfoMapper prescriptionInfoMapper;

    /**
     * 新增处方详情的方法
     * 参数：prescriptionData 处方详情的集合
     * prescriptionId 处方的ID
     */
    @Override
    public void insertPrescriptionInfo(List<PrescriptionForm> prescriptionData, Integer prescriptionId) {
        //遍历prescriptionData 循环将数据录入数据库
        for (PrescriptionForm p : prescriptionData) {
            PrescriptionInfo prescriptionInfo = new PrescriptionInfo();
            prescriptionInfo.setPrescriptionId(prescriptionId);
            prescriptionInfo.setMedicineId(p.getMedicineId());
            prescriptionInfo.setMedicineNumber(p.getProductNumber());
            prescriptionInfo.setMedicinePrice(p.getProductRetailPrice());
            prescriptionInfo.setMedicineUse(p.getProductUse());
            prescriptionInfo.setMedicineFrequency(p.getProductFrequency());
            prescriptionInfo.setMedicineTotal(p.getProductTotal());
            prescriptionInfoMapper.insert(prescriptionInfo);
        }
    }
}
